package com.bt.framework.utils

import android.app.Activity
import android.content.Context
import com.bt.framework.R
import com.bt.framework.loading.CenterLoadingView

/**
 *@author:hxm
 *@date: 2025/6/25 0:04
 *@version:
 *@description: 等待提示框
 */
class LoadingUtil(private val mContext: Context) {
    private var loadView: CenterLoadingView? = null

    /**
     * 统一耗时操作Dialog
     */
    fun showLoading(text: String?) {
        if (loadView == null) {
            loadView = CenterLoadingView(mContext, R.style.dialog)
        }
        if (loadView?.isShowing == true) {
            loadView?.dismiss()
        }
        if (!text.isNullOrEmpty()) {
            loadView?.setTitle(text as CharSequence)
        }
        if (mContext is Activity && mContext.isFinishing) {
            return
        }
        loadView?.show()
    }

    /**
     * 关闭Dialog
     */
    fun dismissLoading() {
        if (mContext is Activity && mContext.isFinishing) {
            return
        }
        loadView?.let {
            if (it.isShowing) {
                it.dismiss()
            }
        }
    }

}